<template>
  <div>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="序号" align="center" prop="order" width="50" />
      <el-table-column label="标准编号" align="center" prop="noticeType" min-width="100">
        <template slot-scope="scope">
          <el-link @click="handledetailed(scope.row)" type="primary">{{ scope.row.levelNum || '-' }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="标准名称" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.levelName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" min-width="120">
        <template slot-scope="scope">
          <!-- <div :style="'color:' + ['#67C23A', '#F56C6C'][scope.row.status]">
            <i :class="['el-icon-success', 'el-icon-remove'][scope.row.status]" />
            <span>
              {{ ['启用中', '禁用中'][scope.row.status] }}
            </span>
          </div> -->
          <dict-tag :options="statusFlag" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="标准说明" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.explanation || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.createBy || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" min-width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime || '-' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="180" fixed="right" align="center">
        <template slot-scope="scope">
          <el-button v-hasPermi="['insurance_standard_update']" size="small" type="primary" icon="el-icon-edit"
            @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button v-hasPermi="['insurance_standard_disabled']" v-if="scope.row.status === '0'" size="small"
            icon="el-icon-lock" type="danger" @click="handleDelete(scope.row)">禁用
          </el-button>
          <el-button v-hasPermi="['insurance_standard_disabled']" v-else size="small" type="success"
            icon="el-icon-unlock" @click="handleDelete(scope.row)">启用
          </el-button>
          <!-- <el-button size="small" type="primary" icon="el-icon-view" @click="handleSelectImage(scope.row.image)">图片
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <div class="card-div">
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <!-- 查看图片 -->
    <template v-if="ImageOpen">
      <DialogImage :src="ImageSrc"></DialogImage>
    </template>
    <!-- 查看设备基值详情 -->
    <template v-if="opendetailed">
      <detailed :rowObj="detailedObj"></detailed>
    </template>
  </div>
</template>

<script>
import { getlevelList, puttUpdatelevel } from "@/api/maintenance/insurance/insurance.js";

export default {
  name: "equipment",
  // dicts: ['sys_notice_status', 'sys_notice_type'],
  components: {
    detailed: () => import('../form/detailed.vue')
  },
  data () {
    return {
      // 遮罩层
      loading: true,
      opendetailed: false,
      detailedObj: {},
      ImageOpen: false,
      ImageSrc: '',
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dictdatalist: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层表格数据
      noticeList: [],
      rowObj: {},
      // 弹出层标题
      title: "修改设备基值",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'upkeepLevelId',
        isAsc: 'desc'//倒叙
      },
    };
  },
  created () {
    this.getList();
  },
  methods: {
    handleSelectImage (src) {
      this.ImageOpen = true
      this.ImageSrc = src
    },
    /** 查询列表 */
    async getList (value) {
      this.loading = true;
      let values = value || {}
      let params = {
        ...this.queryParams,
        ...values,
        // 'params[equipmentNum]': values.equipmentNum,//设备编号
        // 'params[equipmentName]': values.equipmentName
      }
      getlevelList(params).then(response => {
        this.noticeList = response.data && response.data.map((item, index) => {
          return {
            ...item,
            order: index + 1
          }
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 打开详细弹窗
    handledetailed (row) {
      // this.$parent.$parent.tabIndex = true
      // console.log(this.$parent.$parent.activeName);
      // // this.$parent.$parent.activeName = '3'
      // this.$parent.$parent.rowObj = row
      this.$parent.$parent.$parent.$parent.tabIndex = true
      this.$parent.$parent.$parent.$parent.activeName = '3'
      this.$parent.$parent.$parent.$parent.rowObj = row
      //  this.$parent.addTab(row);
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.$emit('UpdateClone', row)
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 启用禁用按钮操作 */
    handleDelete (row) {
      const noticeIds = row.levelName || '无名称'
      this.$confirm(`是否确认${row.status === '0' ? `禁用` : `启用`}名称为${noticeIds}的数据？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        let params = {
          upkeepLevelId: row.upkeepLevelId,
          status: row.status === '0' ? 1 : 0
        }
        puttUpdatelevel(params).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getList()
          }
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        })
      }).catch(() => { this.loading = false; });
    }
  },
  filters: {
  }
};
</script>
<style lang="scss" scoped>
.red {
  color: red;
}
</style>